﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Cherry.Agile.Framework;
namespace Cherry.Agile.Data.Repository.Extention
{
    /// <summary>
    /// ObjectParameter参数代理
    /// </summary>
    public class ParamValue
    {

        private ParamValue() { 
        }

        internal ParameterDirection Direction { get; private set; }
        internal Type ValueType { get; set; }
        internal DbType DbType
        {
            get {
                var name = ValueType.Name.ToString();
                return name.ToEnum<DbType>();
            }
        }


        public object Value { get; private set; } 

        /// <summary>
        /// 获取输出类型的参数
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <returns></returns>
        /// <example>
        /// <code><![CDATA[
        ///  new ObjectParameter("param2", ParamValue.OupoutValue<string>());
        /// ]]></code>
        /// </example>
        public static ParamValue OupoutValue<T>()
        {
            return new ParamValue() { Direction = ParameterDirection.Output,ValueType = typeof(T) };
        }

        /// <summary>
        /// 获取输入输出参数
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        /// <example>
        /// <code><![CDATA[
        ///  new ObjectParameter("param2", ParamValue.InputOutput<string>("VISKI"));
        /// ]]></code>
        /// </example>
        public static ParamValue InputOutput<T>(T value)
        {
            return new ParamValue() { Direction = ParameterDirection.InputOutput ,Value = value,ValueType = typeof(T)};
        }

        /// <summary>
        /// 获取返回参数
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <returns></returns>
        /// <example>
        /// <code><![CDATA[
        ///  new ObjectParameter("param2", ParamValue.ReturnValue<string>());
        /// ]]></code>
        /// </example>
        public static ParamValue ReturnValue<T>()
        {
            return new ParamValue() { Direction = ParameterDirection.ReturnValue, ValueType = typeof(T) };
        }




    }
}
